/*
 *说明：命令日志 首页脚本
 *
 *@author liuxun 2012-04-06
*/

var opeForm;
var grid;

$(function(){
	opeForm = $('#opeForm');

	grid=$('#listTable').datagrid({
		columns:[[

            {title:'机构名称',field:'ORG_NAME',align:'center',width:200},
            
            {title:'用户姓名',field:'USR_NAME',align:'center',width:60},
            
            {title:'节点名称',field:'NODE_DECODE',align:'center',width:120},
            
            {title:'节点IP',field:'NODE_IP',align:'center',width:100},            
            
            {title:'资源名称',field:'RSC_NAME',align:'center',width:80},
            
            {title:'账号名',field:'RSC_ACC_ID',align:'center',width:60},
            
            {title:'协议',field:'PRO_NAME',align:'center',width:60},
            
            {title:'开始时间',field:'BEGIN_TIME',align:'center',width:100},

            {title:'命令',field:'CMD',align:'center',width:180,
            	formatter:function(value,rec){
            		if(value.length < 6){
            			return value;
            		}else{
            			var str = value.substr(value.length-6, value.length);
            			if(str == '[DENY]'){
            				return "<font color='red'>" + value +"</font>";
            			}else{
            				return value;
            			}
            		}
			    }
            }
        ]],
		pagination:true,
		singleSelect: false
	});

	queryOperation();

	$('#queryBtn').click(queryOperation);
	$('#clearBtn').click(clearOperation);
	$('#reloadBtn').click(refreshWin);
	$('#genReportBtn').click(genReporOperation);
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
	var params = opeForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		url: 'E_CMD_LOG!queryList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//查看明细
function showInfo(key) {
	var url = 'E_CMD_LOG!showInfo.do?model.key=' + key;
	openWin(url,'pop'); 
}

//选择机构
function select_a_org() {
	var action = "A_ORG!showTree.do?model.org_status=01";
	var row = showModalWin(action);
	
	if (row) {
		$('#org_name').val(row.attributes.org_name);
		$('#org_sequence').val(row.attributes.org_sequence);
	}
	
}

//选择资源
function select_c_rsc() {
	var action = "C_RSC!showSelect.do?model.rsc_status=01";
	var row = showModalWin(action,'A2');
	
	if (row) {
		$('#rsc_id').val(row.rsc_id);
		$('#rsc_name').val(row.rsc_name);
	}
}

//生成命令日志报表
function genReporOperation(){  
//	var begin_time = $('#begin_time').val();
//	var cmd = $('#cmd').val();
//	
//	var url = 'E_CMD_LOG!genCmdLogReport.do?model.begin_time='+begin_time+'&model.cmd='+cmd;
//	openWin(url,'pop');
	
	opeForm.attr('action', 'E_CMD_LOG!genCmdLogReport.do');
	opeForm.submit();	
}

//操作成功后刷新列表
function afterOK(){
	queryOperation();
}